package com.achievement.service.impl;

import com.achievement.domain.param.honor.AchievementExpertParam;
import com.achievement.domain.vo.honor.ExpertReviewByPlanVO;
import com.achievement.domain.bo.AchievementExpertBO;
import com.achievement.mapper.AchievementExpertMapper;
import com.achievement.mappings.AchievementExpertMapping;
import com.achievement.service.IAchievementExpertService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class AchievementExpertServiceImpl implements IAchievementExpertService {
    @Autowired
    AchievementExpertMapper mapper;
    @Autowired
    AchievementExpertMapping mapping;
    public List<ExpertReviewByPlanVO> getPageByReviewPlanId(AchievementExpertParam param){
        AchievementExpertBO bo=mapping.param2Bo(param);
        if(StringUtils.isNotEmpty(param.getEduDegree())&&!param.getEduDegree().equals("[]")){
            List<String> eduDegrees= Arrays.stream(param.getEduDegree().split(",")).filter(id -> !id.trim().isEmpty()).collect(Collectors.toList());
            bo.setEduDegrees(eduDegrees);
        }
        if(StringUtils.isNotEmpty(param.getSubjectClassId())&&!param.getSubjectClassId().equals("[]")){
            List<String> subjectClassIds= Arrays.stream(param.getSubjectClassId().split(",")).filter(id -> !id.trim().isEmpty()).collect(Collectors.toList());
            bo.setSubjectClassIds(subjectClassIds);
        }
        if(StringUtils.isNotEmpty(param.getTitleId())&&!param.getTitleId().equals("[]")){
            List<String> titleIds= Arrays.stream(param.getTitleId().split(",")).filter(id -> !id.trim().isEmpty()).collect(Collectors.toList());
            bo.setTitleIds(titleIds);
        }
        if(StringUtils.isNotEmpty(param.getSubjectId())&&!param.getSubjectId().equals("[]")){
            List<String> subjectIds= Arrays.stream(param.getSubjectId().split(",")).filter(id -> !id.trim().isEmpty()).collect(Collectors.toList());
            bo.setSubjectIds(subjectIds);
        }
        if(StringUtils.isNotEmpty(param.getEduLevel())&&!param.getEduLevel().equals("[]")){
            List<String> eduLevels= Arrays.stream(param.getEduLevel().split(",")).filter(id -> !id.trim().isEmpty()).collect(Collectors.toList());
            bo.setEduLevels(eduLevels);
        }
        if(StringUtils.isNotEmpty(param.getHonorTitleId())&&!param.getHonorTitleId().equals("[]")){
            List<String> honorTitleIds= Arrays.stream(param.getHonorTitleId().split(",")).filter(id -> !id.trim().isEmpty()).collect(Collectors.toList());
            bo.setHonorTitleIds(honorTitleIds);
        }
        return mapper.getPageByReviewPlanId(bo);
    }
}
